package sg.edu.nus.iss.stockex;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
public class Util {
	private static final String DATE_FORMAT_SHORT = "yyyy-MM-dd";
	//private static final String DATE_FORMAT_LONG = "yyyy-MM-dd";
	private static final String DATE_FORMAT_YYMM = "yyyyMM";

	private static DateFormat dfShort = new SimpleDateFormat(DATE_FORMAT_SHORT);
	//private static DateFormat dfLong = new SimpleDateFormat(DATE_FORMAT_LONG);
	private static DateFormat dfYYMM = new SimpleDateFormat(DATE_FORMAT_YYMM);
	
	public static Date parseDate(String dateStr)
	{
		try{
			return dfShort.parse(dateStr);
		}catch(Exception ex)
		{
			return null;
		}

	}

	public static String formatDate(Date date)
	{
		try{
			return dfShort.format(date);
		}catch(Exception ex)
		{
			return null;
		}

	}
	
	public static String getYearMonth(Date date)
	{
		try{
			return dfYYMM.format(date);
		}catch(Exception ex)
		{
			return null;
		}

	}
	
	public static String formatDateFromLong(long longDate) {

		return dfShort.format(longDate);

	}
}
